package com.javasm.sale;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@TableName("sale_order")
public class Order implements Serializable {
    @TableId(type = IdType.ASSIGN_ID)
    @ExcelProperty("订单编号")
    private String orderId;
    @ExcelProperty("订单类型")
    private String orderType;
    @ExcelProperty("订单状态")
    private String status;
    @ExcelProperty("订单总金额")
    private Double totalMoney;
    @ExcelProperty("收货人")
    private String consignee;
    @ExcelProperty("收货人手机号")
    private String phone;
    @ExcelProperty("详细地址")
    private String area;
    @ExcelProperty("邮编")
    private String zipcode;
    @ExcelProperty("区域")
    private String region;
    @ExcelProperty("配送方式")
    private String distribution;
    @ExcelProperty("支付方式")
    private String pay;
    @ExcelProperty("下单时间")
    private String signForTime;
    private String createId;
    private String createTime;
    private String updateTime;

    @TableField(exist = false)
    private List<CommodityOrder> commodityList = new ArrayList<>();
    @TableField(exist = false)
    private List<String> createTimeArray;
    @TableField(exist = false)
    private Boolean isSalesReturn=true;

    @TableField(exist = false)
    private Delivery delivery;

    @ExcelProperty("失败原因")
    @TableField(exist = false)
    private String errorMsg="数据库保存失败";


    public boolean check() {
        if(orderId==null)errorMsg="订单编号为空";
        if(orderType==null)errorMsg="订单类型为空";
        if(status==null)errorMsg="订单状态为空";
        if(totalMoney==null)errorMsg="订单总金额为空";
        if(consignee==null)errorMsg="收货人为空";
        if(phone==null)errorMsg="收货人手机号为空";
        if(area==null)errorMsg="收货人地址为空";
        if(zipcode==null)errorMsg="邮政编码为空";
        if(region==null)errorMsg="收货区域为空";
        if(distribution==null)errorMsg="配送方式为空";
        if(pay==null)errorMsg="支付方式为空";
        if(!"数据库保存失败".equals(errorMsg)){
            return false;
        }
        return true;
    }

    public boolean parse(Map<String, String> orderStatusMap, Map<String, String> distributionMap, Map<String, String> salePayMap, Map<String, String> saleOrderTypeMap) {
        String statusValue = orderStatusMap.get(this.getStatus());
        if(!StringUtils.hasLength(statusValue))errorMsg="订单状态不存在";

        String distribution = distributionMap.get(this.getDistribution());
        if(StringUtils.isEmpty(distribution))errorMsg="配送方式不存在";

        String pay = salePayMap.get(this.getPay());
        if(StringUtils.isEmpty(pay))errorMsg="支付方式不存在";

        String orderType = saleOrderTypeMap.get(this.getOrderType());
        if(StringUtils.isEmpty(orderType))errorMsg="订单类型不存在";

        if(!"数据库保存失败".equals(errorMsg)){
            return false;
        }else{
            this.setStatus(statusValue);
            this.setDistribution(distribution);
            this.setPay(pay);
            this.setOrderType(orderType);
//            this.setStatus(statusValue);
            return true;
        }
    }


    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Delivery getDelivery() {
        return delivery;
    }

    public void setDelivery(Delivery delivery) {
        this.delivery = delivery;
    }

    public String getSignForTime() {
        return signForTime;
    }

    public void setSignForTime(String signForTime) {
        this.signForTime = signForTime;
    }

    public Boolean getSalesReturn() {
        return isSalesReturn;
    }

    public void setSalesReturn(Boolean salesReturn) {
        isSalesReturn = salesReturn;
    }

    public List<String> getCreateTimeArray() {
        return createTimeArray;
    }

    public void setCreateTimeArray(List<String> createTimeArray) {
        this.createTimeArray = createTimeArray;
    }

    public List<CommodityOrder> getCommodityList() {
        return commodityList;
    }

    public void setCommodityList(List<CommodityOrder> commodityList) {
        this.commodityList = commodityList;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDistribution() {
        return distribution;
    }

    public void setDistribution(String distribution) {
        this.distribution = distribution;
    }

    public String getPay() {
        return pay;
    }

    public void setPay(String pay) {
        this.pay = pay;
    }

    public Double getTotalMoney() {
        return totalMoney;
    }

    public void setTotalMoney(Double totalMoney) {
        this.totalMoney = totalMoney;
    }

    public String getConsignee() {
        return consignee;
    }

    public void setConsignee(String consignee) {
        this.consignee = consignee;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }



    public String getCreateId() {
        return createId;
    }

    public void setCreateId(String createId) {
        this.createId = createId;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }



}

